﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Tailoring
{
    public partial class multiclint : Form
    {
        public string skey="";
        private SqlDataAdapter da;

        public multiclint()
        {
            InitializeComponent();
        }
        public string key { set { skey = value; } get { return skey; } }
        public void Loadclient(string idkey)
        {
            {
                try
                {

                    SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
                    SqlCommand cmd = new SqlCommand("SELECT * from tblclientinfo WHERE(dbo.tblclientinfo.name) =@Key", conn);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@key", idkey);
                    
                    SqlDataAdapter da;
                    da = new SqlDataAdapter(cmd);

                    if (conn == null && conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    DataSet ds = new DataSet();
                    ds = new DataSet();
                    da.Fill(ds, "Client");
                    //BindingSource bs = new BindingSource();
                    //bs.DataSource = ds;

                    dataGridView1.DataSource = ds.Tables[0];
                    
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }
            }
        }
        private void multiclint_Load(object sender, EventArgs e)
        {
            Loadclient(skey);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;

            if (e.ColumnIndex == dataGridView1.Columns["btnOpen"].Index && e.RowIndex >= 0)
            {
                int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex];
                frmviewpemaish vp = new frmviewpemaish();
                string keyval = Convert.ToString(selectedRow.Cells["clientId"].Value);
                vp.psearchkey=keyval;    
                vp.MdiParent = this.ParentForm;

                    vp.Show();
                    string str = "SELECT     dbo.tblclientinfo.*, dbo.tblpemaish.* FROM dbo.tblpemaish INNER JOIN dbo.tblclientinfo ON dbo.tblpemaish.clientId = dbo.tblclientinfo.clientId WHERE(dbo.tblclientinfo.clientId) =@Key";
                    vp.TopMost = true;
                    vp.loadclient(keyval,str);
                    this.Close();
                }
            }
        }
    
}
